Skip to content

feat(hooks): add json-error-recovery hook to prevent infinite retry loops#741

Closed
BowTiedSwan wants to merge 1 commit intocode-yeongyu:devfrom
BowTiedSwan:fix/json-retry-loop
Closed

feat(hooks): add json-error-recovery hook to prevent infinite retry loops#741
BowTiedSwan wants to merge 1 commit intocode-yeongyu:devfrom
BowTiedSwan:fix/json-retry-loop

Conversation

@BowTiedSwan
Copy link

@BowTiedSwan BowTiedSwan commented Jan 13, 2026

Summary

This PR introduces a new hook json-error-recovery to address Issue #735.

Problem

When a tool call fails due to a JSON parse error (e.g., "Expected '}'"), the agent often retries the exact same malformed payload, leading to an infinite retry loop that wastes tokens and stalls the session.

Solution

The new json-error-recovery hook detects specific JSON error patterns in tool outputs:

  • "JSON Parse error"
  • "SyntaxError: Unexpected token"
  • "Expected '}'"
  • "Unexpected EOF"

When detected, it injects a high-priority system reminder into the tool output, instructing the agent to:

  1. Stop and read the error.
  2. Correct the JSON syntax.
  3. Retry with valid JSON (instead of repeating the error).

Changes

  • Added src/hooks/json-error-recovery/index.ts
  • Updated src/hooks/index.ts and src/index.ts to register the new hook.
  • Updated src/config/schema.ts to include the new hook name.
  • Added verification tests in tests/json_recovery.test.ts.

Verification

  • Ran new tests with bun test tests/json_recovery.test.ts -> PASSED.

Summary by cubic

Adds a json-error-recovery hook to stop infinite retry loops when tool calls fail with JSON parse errors by instructing the agent to fix and resend valid JSON. Fixes #735.

  • Bug Fixes
    • Detects common JSON errors: "JSON Parse error", "SyntaxError: Unexpected token", "Expected '}'", "Unexpected EOF".
    • Appends a high-priority reminder at tool.execute.after to halt repeats and correct JSON.
    • Registers the hook in schema and index; adds tests for JSON recovery and edit recovery.

Written for commit b54a235. Summary will update on new commits.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 13, 2026

All contributors have signed the CLA. Thank you! ✅
Posted by the CLA Assistant Lite bot.

@BowTiedSwan
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 6 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

renekris added a commit to renekris/oh-my-glm that referenced this pull request Jan 13, 2026
@code-yeongyu
Copy link
Owner

Thank you for this contribution! Your json-error-recovery hook is well-designed and follows our established edit-error-recovery pattern perfectly.

Current Issues:

  1. ⚠️ Merge Conflicts: This PR has conflicts with dev (8+ commits ahead)
  2. ⚠️ Stale: Last updated 2026-01-13 (19 days old)
  3. ⚠️ CLA: Please sign the CLA to enable merge

What I Like:

Next Steps:

  1. Rebase on latest dev: git pull --rebase upstream dev
  2. Resolve merge conflicts
  3. Sign the CLA if not already done
  4. Push updated changes

Why Keeping Open:
This feature is valuable and aligned with our goals. The conflicts are due to recent updates (like the unstable-agent-babysitter hook), not design issues. Please update when you have time!

Feel free to reopen if you need more time. Thank you again! 🙏

@code-yeongyu
Copy link
Owner

Thank you for this valuable json-error-recovery hook contribution! Your feature is well-designed and addresses a real issue (#735). However, this PR has been inactive for 23 days with no response to the rebase/CLA request. Given the merge conflicts and stale state, closing this for now. Please feel free to reopen with a fresh PR when you're ready! 🙏

github-actions bot added a commit that referenced this pull request Feb 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Tool call JSON parse error causes infinite retry loop (Write/JSONC)

2 participants